// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Table/TABDMP1Parser.h"

#include "gtest/gtest.h"

#include "DataStructure/Input/Table/TABDMP1Data.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Table/ITABDMP1Service.h"

#include "Import/BDFImport/BDFParserBase.h"
using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
using namespace SG::DBManager;
using namespace SG::Import;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class TABDMP1ParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (TABDMP1ParserTest, ParseEntry1)
{
    // 1 假设BDF文件文本内容，通过解析函数加入到数据库中（需要更改）

    std::vector<std::string> Entry = { "TABDMP1  1       CRIT", "         0.      .03     5.      .03     ENDT" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);

    SG::Import::BDF::BULKDATA::ParseTABDMP1 (DB_SERVICEFACTORY, dividedEntryInfo);

    // // 2 使用DBM接口获取对应的结构体数据（需要更改）
    SG::DataStructure::FEM::TABDMP1Data data;

    DB_SERVICEFACTORY->get<ITABDMP1Service> ()->FindById (1, data);
    // 3 检查解析后的数据（需要更改）
    //  FindNode

    ASSERT_TRUE (data.m_id == 1);
    ASSERT_TRUE (data.m_DAMPList.size () == 2);
    ASSERT_NEAR (data.m_DAMPList[0].m_F, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[0].m_G, 0.06, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[1].m_F, 5.0, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[1].m_G, 0.06, TOLERANCE);
}

TEST_F (TABDMP1ParserTest, ParseEntry2)
{
    // 1 假设BDF文件文本内容，通过解析函数加入到数据库中（需要更改）

    std::vector<std::string> Entry = { "TABDMP1  2       Q", "         0.      .03     5.      .03     ENDT" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);

    SG::Import::BDF::BULKDATA::ParseTABDMP1 (DB_SERVICEFACTORY, dividedEntryInfo);

    // // 2 使用DBM接口获取对应的结构体数据（需要更改）
    SG::DataStructure::FEM::TABDMP1Data data;

    DB_SERVICEFACTORY->get<ITABDMP1Service> ()->FindById (2, data);
    // 3 检查解析后的数据（需要更改）
    //  FindNode

    ASSERT_TRUE (data.m_id == 2);
    ASSERT_TRUE (data.m_DAMPList.size () == 2);
    ASSERT_NEAR (data.m_DAMPList[0].m_F, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[0].m_G, 33.333333333, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[1].m_F, 5.0, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[1].m_G, 33.333333333, TOLERANCE);
}

TEST_F (TABDMP1ParserTest, ParseEntry3)
{
    // 1 假设BDF文件文本内容，通过解析函数加入到数据库中（需要更改）

    std::vector<std::string> Entry = { "TABDMP1  3       ", "         0.      .03     5.      .03     ENDT" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);

    SG::Import::BDF::BULKDATA::ParseTABDMP1 (DB_SERVICEFACTORY, dividedEntryInfo);

    // // 2 使用DBM接口获取对应的结构体数据（需要更改）
    SG::DataStructure::FEM::TABDMP1Data data;

    DB_SERVICEFACTORY->get<ITABDMP1Service> ()->FindById (3, data);
    // 3 检查解析后的数据（需要更改）
    //  FindNode

    ASSERT_TRUE (data.m_id == 3);
    ASSERT_TRUE (data.m_DAMPList.size () == 2);
    ASSERT_NEAR (data.m_DAMPList[0].m_F, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[0].m_G, 0.030, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[1].m_F, 5.0, TOLERANCE);
    ASSERT_NEAR (data.m_DAMPList[1].m_G, 0.030, TOLERANCE);
}